/**
 * @param {number[][]} students
 * @param {number[][]} mentors
 * @return {number}
 */
 var maxCompatibilitySum = function(students, mentors) {
    const n = students.length, len = students[0].length
    let ans = 0
    const target = Array.from({length:n},(_,index)=>index)
    const getCom = (arr) => {
        let sum = 0
        for(let i = 0; i<n; i++){
            const x = students[i], y = mentors[arr[i]]
            for(let j = 0;j<len; j++){
                if(x[j] === y[j]){
                    sum++
                }
            }
        }
        return sum
    }
    const dfs = (nums, pre = []) => {
        for(let i = 0; i<nums.length; i++){
            let temp = [...pre, nums[i]]
            if(nums.length == 1){
                ans = Math.max(ans, getCom(temp))
            }else{
                let a = nums.slice()
                a.splice(i,1)
                dfs(a, temp)
            }
        }
    }
    dfs(target)
    return ans
};